
*******************************************************************************
* This version: January 2021
* By Max Kellogg: mdkellogg@uchicago.edu
*******************************************************************************

*******************************************************************************
* This file runs the various scripts cleaning and combining parts of the PSID
*
* Structure of File:
* 1. Set global macros
* 2. Create `raw' panel
* 3. Make generated variables
*
*******************************************************************************

*******************************************************************************
* 1. Set global macros 
*******************************************************************************

*** Globals for loading data and saving output
clear all
set more off
set maxvar 30000
set matsize 11000
macro drop _all

global do 
global output 
global data ".\raw"
global TAXSIM = "./intermediary/"
global intermediary "./intermediary/"
global temp $intermediary
global socsec ".\raw\SocSecType94_07\"

*******************************************************************************
* 2. Create household-level panel from household and individual data
*******************************************************************************
cd "$programs"
do 2_Household_Panel
do 2a_Household_Transfers
do 2b_Household_DI
do 3_Individual_Panel

*******************************************************************************
* 3. Generate Variables 
*******************************************************************************
set more off
do 4_Sample_Selection


*******************************************************************************
* 4. Event study setup 
*******************************************************************************
do 5_eventstudy_setup.do

*******************************************************************************
* 5. Event study 
*******************************************************************************
*Run 0_master_eventstudy.R in the eventstudy subfolder.

*******************************************************************************
* 6. model moments
*******************************************************************************
*This is a natural breaking point in the replication. Globals have been redefined in the below file:
do "./makemoments/dotypes.do"

*******************************************************************************
* 7. fitting the model
*******************************************************************************
*run the R scipt 0_master_model.R

*******************************************************************************
* 8. assessing model fit to wealth, consumption, and health profiles
*******************************************************************************
global type type_stationary
global typename stationary
global dir "D:\Dropbox\DynamicDI\replication_final\makemoments"
global out "D:\Dropbox\DynamicDI\replication_final\output"
global mout "D:\Dropbox\DynamicDI\replication_final\modeloutput"
global revdta	"D:\Dropbox\DynamicDI\replication_final"

*Files below use inputs from the fitted model to produce graphs.*
*Run the above scripts, then solve the model, then run these scripts.

clear all
cd "$dir"
do "wealth_regressions_spouse.do"


global modeltype "simplified"
cd "$dir"
clear all
do "model_fitting.do"


*repeating disability risk to produce a graph:
global type type_oldsample
global typename oldsample
cd "$dir"
clear all
do "disability_risk_marginalspouse.do"
